package cate.common.table.item.rune;

import cate.common.annotation.SplitParse;
import cate.common.util.SplitParser;
import cate.common.util.random.RWItem;
import cate.common.util.random.RWList;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/** 符文技能分组配置 */
public class SkillGroupList extends RWList<SkillGroupList.Item> {

    public void parse(String config) {
        List<Item> l = SplitParser.parse(Item.class, config);
        this.setup(l);
    }

    public static class Item implements RWItem {

        @SplitParse(order = 0, note = "分组")
        public String groupIds;

        @SplitParse(order = 1, note = "权重", defaultValue = "1.0")
        public double weight;

        @Override
        public double getWeight() {
            return weight;
        }

        /** 解析groupIds */
        public List<Integer> getGroupId() {
            return Arrays.stream(groupIds.split(",")).filter(id -> !"0".equals(id))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());
        }
    }
}
